package com.example.springbootnacos;


import com.alibaba.nacos.api.annotation.NacosInjected;
import com.alibaba.nacos.api.exception.NacosException;
import com.alibaba.nacos.api.naming.NamingService;
import com.alibaba.nacos.api.naming.pojo.Instance;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

    @NacosInjected
    NamingService namingService;

    @GetMapping("getNacos")
    public String getNacos() throws NacosException {

        return namingService.getAllInstances("mynacos").toString();
    }

    @GetMapping("injectNacos")
    public String injectNacos() throws NacosException {
        Instance instance = new Instance();
        instance.setClusterName("Test");
        instance.setEnabled(true);
        instance.setEphemeral(true);
        instance.setIp("49.232.10.11");
        instance.setPort(8848);
        instance.setWeight(10);
        namingService.registerInstance("mynacos",instance);
        return "SUICCESS";
    }
}
